package com.du.cloud.security.feign;

import com.du.cloud.security.component.ResourceServerAutoConfiguration;
import feign.RequestInterceptor;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.cloud.security.oauth2.client.AccessTokenContextRelay;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;

/**
 * Desc:
 * Author: dushuang
 * Date: 2020/5/29
 **/
@Configuration
@ConditionalOnBean(value = ResourceServerAutoConfiguration.class)
public class CustomFeignClientConfiguration {
    @Bean
    public RequestInterceptor oauth2FeignRequestInterceptor(@Qualifier("oauth2ClientContext") OAuth2ClientContext oAuth2ClientContext,
                                                            OAuth2ProtectedResourceDetails resource,
                                                            AccessTokenContextRelay accessTokenContextRelay) {
        return new CustomFeignClientInterceptor(oAuth2ClientContext, resource, accessTokenContextRelay);
    }
}
